/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.util;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import tw.com.hitevision.whiteboard.android.R;

public class BroadcastHelper {
    private static final String TAG = BroadcastHelper.class.getSimpleName();

    /** Notifies that the app is switching to either whiteboard or annotation mode. */
    public static void sendModeSwitch(Context context, boolean isAnnotationMode) {
        final Intent i = new Intent(context.getString(R.string.broadcast_action_switch_mode));
        i.putExtra(context.getString(R.string.broadcast_extra_is_annotation_mode), isAnnotationMode);
        context.sendBroadcast(i);
    }

    /** Notifies that the app is now hidden.  This can be used to reset the floatbar. */
    public static void sendAppIsHidden(Context context) {
        context.sendBroadcast(new Intent(
                context.getString(R.string.broadcast_action_inactive_app)));
    }

    /** Notifies that a screenshot is being taken. */
    public static void sendScreenshotStart(Context context) {
        context.sendBroadcast(new Intent(
                context.getString(R.string.broadcast_action_screenshot_start)));
    }

    /** Notifies that a screenshot was taken and the app is now finishing. */
    public static void sendScreenshotEndAndAppIsFinishing(Context context) {
        context.sendBroadcast(new Intent(
                context.getString(R.string.broadcast_action_screenshot_end_and_exit_app)));
    }

    /** Notifies that a screenshot was taken. */
    public static void sendScreenshotEnd(Context context) {
        context.sendBroadcast(new Intent(
                context.getString(R.string.broadcast_action_screenshot_end)));
    }

    /** Notifies that the app is now running in foreground. */
    public static void sendAppInForeground(Context context, boolean isAnnotationMode) {
        final Intent i = new Intent(context.getString(R.string.broadcast_action_app_foreground));
        i.putExtra(context.getString(R.string.broadcast_extra_is_annotation_mode), isAnnotationMode);
        context.sendBroadcast(i);
    }

    /** Notifies that the app is now running in background. */
    public static void sendAppInBackground(Context context, boolean isAnnotationMode) {
        final Intent i = new Intent(context.getString(R.string.broadcast_action_app_background));
        i.putExtra(context.getString(R.string.broadcast_extra_is_annotation_mode), isAnnotationMode);
        context.sendBroadcast(i);
    }

    /** Notifies that the app has enabled display control. */
    public static void sendDisplayControlStart(Context context) {
        final Intent i = new Intent(context.getString(R.string.broadcast_action_display_control));
        i.putExtra(context.getString(R.string.broadcast_extra_disable), false);
        context.sendBroadcast(i);
    }

    /** Notifies that the app has disabled display control. */
    public static void sendDisplayControlEnd(Context context) {
        final Intent i = new Intent(context.getString(R.string.broadcast_action_display_control));
        i.putExtra(context.getString(R.string.broadcast_extra_disable), true);
        context.sendBroadcast(i);
    }

    /** Notifies that the app has disabled display control. */
    public static void sendSourceAppMuteOn(Context context) {
        log("sendSourceAppMuteOn");
        context.sendBroadcast(new Intent(context.getString(R.string.broadcast_action_source_mute_on)));
    }

    /** Notifies that the app has disabled display control. */
    public static void sendSourceAppMuteOff(Context context) {
        log("sendSourceAppMuteOff");
        context.sendBroadcast(new Intent(context.getString(R.string.broadcast_action_source_mute_off)));
    }

    /** Notifies that checking ops touch if need close */
    public static void sendCheckOpsTouch(Context context) {
        context.sendBroadcast(new Intent("com.hht.action.USBTOUCH.ENABLE"));
    }


    private static void log(String msg) {
        Log.d(TAG, msg);
    }
}
